package com.example.dinnermanager;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	
	private List<OrderDate> orList;
	private LayoutInflater inflater;
	Context context;
	

	public  MyAdapter(Context context,List<OrderDate> orderDates){
		super();
		this.context=context;
		this.orList=orderDates;
		this.inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return orList.size();
	}

	@Override
	public Object getItem(int position) {
		return orList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder =null;
		if(convertView==null){
			holder=new ViewHolder();
			convertView = inflater.inflate(R.layout.order_item, null);
			holder.placeTextView=(TextView)convertView.findViewById(R.id.txt_place);
			holder.timeTextView=(TextView)convertView.findViewById(R.id.txt_time);
			holder.conditionTextView=(TextView)convertView.findViewById(R.id.txt_condition);
			holder.imageButton=(ImageButton)convertView.findViewById(R.id.next);
			convertView.setTag(holder);
		}
		else {
			holder=(ViewHolder)convertView.getTag();
		}
			holder.placeTextView.setText(orList.get(position).getPlaceString());
			holder.timeTextView.setText(orList.get(position).getTimeString());
			holder.conditionTextView.setText(orList.get(position).getCondetionString());
			holder.imageButton.setFocusable(false);
		    holder.imageButton.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent intent=new Intent();
					intent.setClass(context, OrderInfoActivity.class);
					context.startActivity(intent);
				}
			});
		    return convertView;
			
	}
	public final class ViewHolder{
		public TextView placeTextView;
		public TextView timeTextView;
		public TextView conditionTextView;
		public ImageButton imageButton;
	}

}
